/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upc.embajada.dao.impl;

import edu.upc.embajada.dao.DistritoDao;
import edu.upc.embajada.entity.Distrito;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.stereotype.Repository;

/**
 *
 * @author u02728
 */
@Repository
public class DistritoDaoImpl extends SimpleJdbcDaoSupport implements DistritoDao {

    private static Logger log = LoggerFactory.getLogger(SolicitudDaoImpl.class);

    @Autowired
    public DistritoDaoImpl(DataSource dataSource) {
        log.info("Asignando el dataSource");
        setDataSource(dataSource);
    }

    @Override
    public Distrito obtener(Integer id) {
        try {
            return getSimpleJdbcTemplate().queryForObject(
                    "select * from distrito where idDistrito = ?",
                    new BeanPropertyRowMapper<Distrito>(Distrito.class), id);
        } catch (EmptyResultDataAccessException e) {
            return null;
        }
    }
    
}
